package sunstar.com.xq.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.squareup.picasso.Picasso
import com.squareup.picasso.Transformation
import sunstar.com.xq.R
import sunstar.com.xq.databean.CommentListData
import sunstar.com.xq.util.CircleTransform

/**
 * Created by Sun.Star on 2017/6/16.
 */
class CommentAdapter(var context: Context,var list: MutableList<CommentListData>) : RecyclerView.Adapter<CommentAdapter.CommentHolder>(){
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): CommentHolder = CommentHolder(LayoutInflater.from(context).inflate(R.layout.comment,parent,false))

    override fun onBindViewHolder(holder: CommentHolder?, position: Int) {
        holder!!.userName!!.text = list[position].user!!.nickName
        Picasso.with(context).load(list[position].user!!.userAvater).transform(CircleTransform()).into(holder!!.avater)
        holder!!.commentTime!!.text = list[position].comment!!.createdAt
        holder!!.commentInfo!!.text = list[position].comment!!.CommentInfo
    }

    override fun getItemCount(): Int = list.size


    class CommentHolder (itemView:View): RecyclerView.ViewHolder(itemView){
        var userName:TextView?=null
        var avater:ImageView?=null
        var commentInfo:TextView?=null
        var commentTime:TextView?=null
        init {
            userName = itemView.findViewById(R.id.user_name) as TextView
            commentInfo = itemView.findViewById(R.id.comment_info) as TextView
            commentTime = itemView.findViewById(R.id.comment_time) as TextView
            avater = itemView.findViewById(R.id.user_avater) as ImageView

        }
    }
}